// * and ->
#include <iostream>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include <memory>
using namespace std;

class A {
public:
	A( ) : m_f(open("./file", O_CREAT|O_RDWR, 0644)){
		cout << "A( ) is invoked " << endl;
	}
	~A( ) {
		close( m_f );
		cout << "~A( ) is invoked " << endl;
	}
	void foo( ) {
		write( m_f, "hello world ", 10 );
		cout << "foo( ) is invoked " << endl;
	}
private:
	int m_f;
};

/*
class Auto_ptr {
	public:
		Auto_ptr( A* a ) : m_a(a) {
			
		}
		Auto_ptr( Auto_ptr& that ) : m_a( that.m_a ) {
			that.m_a = NULL;
		}
		~Auto_ptr( ) {
			delete m_a;
		}
		A& operator*( ){
			return *m_a;
		}
		A* operator->() {
			return m_a;
		}
	private:
		A* m_a;
};
*/

// designer
// ------------------------------------------------------------------
// user

int main( void ) {
        /*	
	A* pa = new A;
	(*pa).foo( );
	pa->foo( );
	delete pa;
	*/

	/*
	Auto_ptr pau( new A );
	(*pau).foo( );
	pau->foo( );

	Auto_ptr pbu = pau;
	(*pbu).foo( );
	pbu->foo( );
	*/

	auto_ptr<A> pau( new A );
	(*pau).foo( );
	pau->foo( );

	auto_ptr<A> pbu = pau;
	(*pbu).foo( );

	return 0;
}

